import React, { Component } from 'react';
import Taro from '@tarojs/taro';
import {View, Text} from '@tarojs/components'
import './index.scss';
import {TARO_ENV} from "../../constants/api";
import {GetRequest, vcmonitor} from "../../utils/tools";
import {http} from '../../utils/http'
import {getContent} from "../../utils/handlerPublicCode";

type StateProps = {
  detail: any
}

export default class Store extends Component {
  state: StateProps = {
    detail: {},
  }

  async componentDidMount() {
    vcmonitor(this)
    const sid = Taro.getCurrentInstance().router.params.sid;
    Taro.showLoading({title: '加载中...'});
    const api = '/msvc-shop/v1/application/shop/app/shop/introduction/' + sid
    const res = await http.HGet(api);
    this.setState({
      detail: {
        ...res.data,
      },
    });
    Taro.hideLoading();
  }

  render() {
    const {detail} = this.state;
    return (
      <View className='product-detail'>
        <View className='product-detail-item-wrap'>
          <View style='padding: 10px 14px;background-color: #fff;border-radius: 6px;'>
            <View className='rich-content' id='description'>
              {TARO_ENV === 'weapp' && <View className='content-info content-info-no-l-r' style='padding-top: 0;padding-bottom: 0'>
                <parser selectable html={detail.shop_introduction || ''} />
              </View>}
              {TARO_ENV === 'tt' && <View className='content-info content-info-no-l-r' style='padding-top: 0;padding-bottom: 0'>
                <rich-text preview selectable nodes={getContent(detail.shop_introduction)} />
              </View>}
              {TARO_ENV === 'h5' && <Text selectable className='content-info content-info-no-l-r'>
                {!!detail.shop_introduction &&
                <View id='html-description' dangerouslySetInnerHTML={{__html: detail.shop_introduction}} />}
              </Text>}
            </View>
          </View>
        </View>
        <View style='height: 17px;' />
      </View>
    )
  }
}
